<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>相同标签名的元素切换时实现过渡效果</title>
    <script src="vue.js"></script>
    <style>
      .fade-enter,
      .fade-leave-to {
        opacity: 0;
      }
      .fade-enter-active,
      .fade-leave-active {
        transition: opacity 0.5s;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="show=!show">切换</button>
      <div>
        <transition name="fade">
          <p v-if="show" key="login">登录</p>
          <p v-else key="register">注册</p>
        </transition>
      </div>
    </div>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          show: true,
        },
      });
    </script>
  </body>
</html>
